package com.tedu.boot.controller;

import com.tedu.boot.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;

@Controller
public class UserLogin {
    @RequestMapping("/users")
    public void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println(username + "," + password);


        FileInputStream fis = new FileInputStream("./users/" + username + ".obj");
        ObjectInputStream ois = new ObjectInputStream(fis);
        try {
            User tr = (User) ois.readObject();
            if (password.equals(tr.getPassword()) && username.equals(tr.getUsername())) {
                response.sendRedirect("login_success.html");
            } else {
                response.sendRedirect("excpeion.html");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


}
